package com.w.m.aspect;/**
 * @Author : 明
 * @data : 2022/3/28 13:49
 * @version : 1.0
 */

import org.aspectj.lang.JoinPoint;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Description: TODO
 * @author: Mr.wu
 * @date: 2022年03月28日 13:49
 */
@Aspect
@Component
public class MyAspect {
	@Pointcut("execution(* com.w.m.model..*.*(..))")
	public void pointCut() {
	}

	@Before("pointCut()")
	public void doBefore(JoinPoint joinPoint) {
		System.out.println("AOP Before Advice...");
	}

	@After("pointCut()")
	public void doAfter(JoinPoint joinPoint) {
		System.out.println("AOP After Advice...");
	}

	@AfterReturning(pointcut = "pointCut()", returning = "returnVal")
	public void afterReturn(JoinPoint joinPoint, Object returnVal) {
		System.out.println("AOP AfterReturning Advice:" + returnVal);
	}

	@AfterThrowing(pointcut = "pointCut()", throwing = "error")
	public void afterThrowing(JoinPoint joinPoint, Throwable error) {
		System.out.println("AOP AfterThrowing Advice..." + error);
		System.out.println("AfterThrowing...");
	}

	@Around("pointCut()")
	public void around(ProceedingJoinPoint pjp) {
		System.out.println("AOP Aronud before...");
		try {
			pjp.proceed();
		} catch (Throwable e) {
			e.printStackTrace();
		}
		System.out.println("AOP Aronud after...");
	}


}
